#include "ui_widget.h"
#include "widget.h"
#include "mainwindow.h"
#include "QApplication"
#include "QTime"
#include "QPainter"
#include "sqlitedboperator.h"
#include "QMessageBox"
#include "clockmenu.h"

void sleep_ms(unsigned int msec)
{
    QTime reachTime = QTime::currentTime().addMSecs(msec);
    while(QTime::currentTime() <reachTime)
        QCoreApplication::processEvents(QEventLoop::AllEvents,100);
}

Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);
    initstart();

}
void Widget::paintEvent(QPaintEvent *)
{
    QPainter p;
    p.begin(this);
    p.drawPixmap(0,0,width(),height(),QPixmap(":/images/withtree.png"));
}


Widget::~Widget()
{
    delete ui;
}

void Widget::initstart()
{
    ui->userEdit->setInputMask("kingzm");
    ui->passwdEdit->setInputMask("123456");
    ui->userEdit->setText("kingzm");
    ui->passwdEdit->setText("123456");

}


void Widget::on_login_Button_clicked()
{

    QString userName = ui->userEdit->text();
    QString passwdName = ui->passwdEdit->text();
    if((userName == "kingzm") &&(passwdName == "123456"))
    {
        MainWindow *home_ui = new MainWindow();
        home_ui ->setGeometry(this->geometry());
        home_ui->setWindowState(Qt::WindowNoState);
        home_ui->show();
        this->close();
    }
    else
    {
        QMessageBox::warning(this, tr("登录提示"),
                             tr("用户名密码不匹配，请重新输入"), QMessageBox::Yes);
    }
}

void Widget::on_exti_clicked()
{
    lock->show();
    this->close();
}



void Widget::on_passwdEdit_cursorPositionChanged(int arg1, int arg2)
{
        ui->passwdEdit ->setEchoMode(QLineEdit::Password); //密码显示***
}






